package net.lab0.nebula.gui;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.TitledBorder;

import net.lab0.nebula.core.QuadTreeManager;

@SuppressWarnings("serial")
public class MainPanel extends JPanel
{
    private JLabel     lblTotalNumberOfFilesValue;
    private JLabel     lblTotalComputingTimeValue;
    private JLabel     lblComputedNodesCountValue;
    private JLabel     lblIterationDifferenceLimitValue;
    private JLabel     lblPointsPerSideValue;
    private JLabel     lblMaxDepthValue;
    private JLabel     lblMaxNumberIterValue;
    
    private MainWindow mainWindow;
    
    //useful for window builder
    @SuppressWarnings("unused")
    private MainPanel()
    {
        this(null);
    }
    
    public MainPanel(MainWindow mainWindow)
    {
        this.mainWindow = mainWindow;
        
        GridBagLayout gbl_panel = new GridBagLayout();
        gbl_panel.columnWidths = new int[] { 0, 0 };
        gbl_panel.rowHeights = new int[] { 0, 0 };
        gbl_panel.columnWeights = new double[] { 1.0, Double.MIN_VALUE };
        gbl_panel.rowWeights = new double[] { 0.0, Double.MIN_VALUE };
        this.setLayout(gbl_panel);
        
        JPanel panel_1 = new JPanel();
        panel_1.setBorder(new TitledBorder(null, "Tree Informations", TitledBorder.LEADING, TitledBorder.TOP, null, null));
        GridBagConstraints gbc_panel_1 = new GridBagConstraints();
        gbc_panel_1.fill = GridBagConstraints.BOTH;
        gbc_panel_1.gridx = 0;
        gbc_panel_1.gridy = 0;
        this.add(panel_1, gbc_panel_1);
        GridBagLayout gbl_panel_1 = new GridBagLayout();
        gbl_panel_1.columnWidths = new int[] { 0, 0, 0 };
        gbl_panel_1.rowHeights = new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
        gbl_panel_1.columnWeights = new double[] { 0.0, 0.0, Double.MIN_VALUE };
        gbl_panel_1.rowWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE };
        panel_1.setLayout(gbl_panel_1);
        
        JLabel lblMaximumOfIterations = new JLabel("Maximum number of iterations:");
        GridBagConstraints gbc_lblMaximumOfIterations = new GridBagConstraints();
        gbc_lblMaximumOfIterations.anchor = GridBagConstraints.EAST;
        gbc_lblMaximumOfIterations.insets = new Insets(0, 0, 5, 5);
        gbc_lblMaximumOfIterations.gridx = 0;
        gbc_lblMaximumOfIterations.gridy = 0;
        panel_1.add(lblMaximumOfIterations, gbc_lblMaximumOfIterations);
        
        lblMaxNumberIterValue = new JLabel("maxNumberIterValue");
        GridBagConstraints gbc_lblMaxnumberitervalue = new GridBagConstraints();
        gbc_lblMaxnumberitervalue.anchor = GridBagConstraints.WEST;
        gbc_lblMaxnumberitervalue.insets = new Insets(0, 0, 5, 0);
        gbc_lblMaxnumberitervalue.gridx = 1;
        gbc_lblMaxnumberitervalue.gridy = 0;
        panel_1.add(lblMaxNumberIterValue, gbc_lblMaxnumberitervalue);
        
        JLabel lblMaximumDepth = new JLabel("Maximum Depth:");
        GridBagConstraints gbc_lblMaximumDepth = new GridBagConstraints();
        gbc_lblMaximumDepth.anchor = GridBagConstraints.EAST;
        gbc_lblMaximumDepth.insets = new Insets(0, 0, 5, 5);
        gbc_lblMaximumDepth.gridx = 0;
        gbc_lblMaximumDepth.gridy = 1;
        panel_1.add(lblMaximumDepth, gbc_lblMaximumDepth);
        
        lblMaxDepthValue = new JLabel("maxDepthValue");
        GridBagConstraints gbc_lblMaxdepthvalue = new GridBagConstraints();
        gbc_lblMaxdepthvalue.anchor = GridBagConstraints.WEST;
        gbc_lblMaxdepthvalue.insets = new Insets(0, 0, 5, 0);
        gbc_lblMaxdepthvalue.gridx = 1;
        gbc_lblMaxdepthvalue.gridy = 1;
        panel_1.add(lblMaxDepthValue, gbc_lblMaxdepthvalue);
        
        JLabel lblPointsPerSide = new JLabel("Points per side:");
        GridBagConstraints gbc_lblPointsPerSide = new GridBagConstraints();
        gbc_lblPointsPerSide.anchor = GridBagConstraints.EAST;
        gbc_lblPointsPerSide.insets = new Insets(0, 0, 5, 5);
        gbc_lblPointsPerSide.gridx = 0;
        gbc_lblPointsPerSide.gridy = 2;
        panel_1.add(lblPointsPerSide, gbc_lblPointsPerSide);
        
        lblPointsPerSideValue = new JLabel("pointsPerSideValue");
        GridBagConstraints gbc_lblPointspersidevalue = new GridBagConstraints();
        gbc_lblPointspersidevalue.anchor = GridBagConstraints.WEST;
        gbc_lblPointspersidevalue.insets = new Insets(0, 0, 5, 0);
        gbc_lblPointspersidevalue.gridx = 1;
        gbc_lblPointspersidevalue.gridy = 2;
        panel_1.add(lblPointsPerSideValue, gbc_lblPointspersidevalue);
        
        JLabel lblIterationDifferenceLimit = new JLabel("Iteration difference limit:");
        GridBagConstraints gbc_lblIterationDifferenceLimit = new GridBagConstraints();
        gbc_lblIterationDifferenceLimit.anchor = GridBagConstraints.EAST;
        gbc_lblIterationDifferenceLimit.insets = new Insets(0, 0, 5, 5);
        gbc_lblIterationDifferenceLimit.gridx = 0;
        gbc_lblIterationDifferenceLimit.gridy = 3;
        panel_1.add(lblIterationDifferenceLimit, gbc_lblIterationDifferenceLimit);
        
        lblIterationDifferenceLimitValue = new JLabel("iterationDifferenceLimit");
        GridBagConstraints gbc_lblIterationdifferencelimitvalue = new GridBagConstraints();
        gbc_lblIterationdifferencelimitvalue.anchor = GridBagConstraints.WEST;
        gbc_lblIterationdifferencelimitvalue.insets = new Insets(0, 0, 5, 0);
        gbc_lblIterationdifferencelimitvalue.gridx = 1;
        gbc_lblIterationdifferencelimitvalue.gridy = 3;
        panel_1.add(lblIterationDifferenceLimitValue, gbc_lblIterationdifferencelimitvalue);
        
        JLabel lblComputedNodesCount = new JLabel("Computed nodes count:");
        GridBagConstraints gbc_lblComputedNodesCount = new GridBagConstraints();
        gbc_lblComputedNodesCount.anchor = GridBagConstraints.EAST;
        gbc_lblComputedNodesCount.insets = new Insets(0, 0, 5, 5);
        gbc_lblComputedNodesCount.gridx = 0;
        gbc_lblComputedNodesCount.gridy = 4;
        panel_1.add(lblComputedNodesCount, gbc_lblComputedNodesCount);
        
        lblComputedNodesCountValue = new JLabel("computedNodesCountValue");
        GridBagConstraints gbc_lblComputednodescountvalue = new GridBagConstraints();
        gbc_lblComputednodescountvalue.anchor = GridBagConstraints.WEST;
        gbc_lblComputednodescountvalue.insets = new Insets(0, 0, 5, 0);
        gbc_lblComputednodescountvalue.gridx = 1;
        gbc_lblComputednodescountvalue.gridy = 4;
        panel_1.add(lblComputedNodesCountValue, gbc_lblComputednodescountvalue);
        
        JLabel lblTotalComputingTime = new JLabel("Total computing time:");
        GridBagConstraints gbc_lblTotalComputingTime = new GridBagConstraints();
        gbc_lblTotalComputingTime.anchor = GridBagConstraints.EAST;
        gbc_lblTotalComputingTime.insets = new Insets(0, 0, 5, 5);
        gbc_lblTotalComputingTime.gridx = 0;
        gbc_lblTotalComputingTime.gridy = 5;
        panel_1.add(lblTotalComputingTime, gbc_lblTotalComputingTime);
        
        lblTotalComputingTimeValue = new JLabel("total computing time value");
        GridBagConstraints gbc_lblTotalComputingTime_1 = new GridBagConstraints();
        gbc_lblTotalComputingTime_1.anchor = GridBagConstraints.WEST;
        gbc_lblTotalComputingTime_1.insets = new Insets(0, 0, 5, 0);
        gbc_lblTotalComputingTime_1.gridx = 1;
        gbc_lblTotalComputingTime_1.gridy = 5;
        panel_1.add(lblTotalComputingTimeValue, gbc_lblTotalComputingTime_1);
        
        JLabel lblFileSaveMode = new JLabel("File save mode:");
        GridBagConstraints gbc_lblFileSaveMode = new GridBagConstraints();
        gbc_lblFileSaveMode.insets = new Insets(0, 0, 5, 5);
        gbc_lblFileSaveMode.anchor = GridBagConstraints.EAST;
        gbc_lblFileSaveMode.gridx = 0;
        gbc_lblFileSaveMode.gridy = 6;
        panel_1.add(lblFileSaveMode, gbc_lblFileSaveMode);
        
        JLabel lblTotalNumberOf = new JLabel("Total number of files:");
        GridBagConstraints gbc_lblTotalNumberOf = new GridBagConstraints();
        gbc_lblTotalNumberOf.anchor = GridBagConstraints.EAST;
        gbc_lblTotalNumberOf.insets = new Insets(0, 0, 0, 5);
        gbc_lblTotalNumberOf.gridx = 0;
        gbc_lblTotalNumberOf.gridy = 7;
        panel_1.add(lblTotalNumberOf, gbc_lblTotalNumberOf);
        
        lblTotalNumberOfFilesValue = new JLabel("total number of files value");
        GridBagConstraints gbc_lblTotalNumberOf_1 = new GridBagConstraints();
        gbc_lblTotalNumberOf_1.anchor = GridBagConstraints.WEST;
        gbc_lblTotalNumberOf_1.gridx = 1;
        gbc_lblTotalNumberOf_1.gridy = 7;
        panel_1.add(lblTotalNumberOfFilesValue, gbc_lblTotalNumberOf_1);
        
    }
    
    public void updateTreeInformations()
    {
        QuadTreeManager quadTreeManager = mainWindow.getQuadTreeManager();
        
        if (quadTreeManager == null)
        {
            lblComputedNodesCountValue.setText("");
            lblIterationDifferenceLimitValue.setText("");
            lblMaxDepthValue.setText("");
            lblMaxNumberIterValue.setText("");
            lblPointsPerSideValue.setText("");
            lblTotalComputingTimeValue.setText("");
            lblTotalNumberOfFilesValue.setText("");
        }
        else
        {
            lblComputedNodesCountValue.setText("" + quadTreeManager.getComputedNodesCount());
            lblIterationDifferenceLimitValue.setText("" + quadTreeManager.getDiffIterLimit());
            lblMaxDepthValue.setText("" + quadTreeManager.getMaxDepth());
            lblMaxNumberIterValue.setText("" + quadTreeManager.getMaxIter());
            lblPointsPerSideValue.setText("" + quadTreeManager.getPointsPerSide());
            lblTotalComputingTimeValue.setText("" + quadTreeManager.getTotalComputingTime());
            lblTotalNumberOfFilesValue.setText("" + quadTreeManager.getFilesCount());
        }
    }

}
